#include <unistd.h>
#include <Task/Task.h>
#include <BSP/Fan.h>
#include <BSP/Sensor.h>
#include <BSP/Time.h>
#include <BSP/LED.h>
#include <BSP/Switch.h>
#include <BSP/Sensor.h>
#include <BSP/Fan.h>
#include <BSP/Time.h>
#include <BSP/Curtain.h>

pthread_t g_task_thread = 0;

void link_switch_to_led(int switch_id, int led_id)
{
    if (Switch_IsPressed(switch_id))
    {
        LED_On(led_id);
    }
    else
    {
        LED_Off(led_id);
    }
}

void control_fan()
{
    int temp = sensor_get_temperature_c();
    if (temp >= 0 && temp < 24)
    {
        set_fan(0);
    }
    else if (temp >= 24 && temp < 26)
    {
        set_fan(1);
    }
}

// ReSharper disable once CppParameterMayBeConstPtrOrRef
void* user_main(void* arg)
{
    (void)arg;
    /* 开始实现程序功能 */
    while (1)
    {
        // LED 任务
        link_switch_to_led(4, 0);
        link_switch_to_led(5, 1);
        // 风扇任务
        control_fan();

        int time = time_get_hour();
        Curtain_Open();
    }

    /* 程序结束 */

    return 0;
}
